<?php

namespace App\Http\Controllers\admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class BaseController extends Controller
{
    protected Request $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    protected function success($msg = 'success', $data = []): \Illuminate\Http\JsonResponse
    {
        return response()->json(['code' => 0, 'msg' => $msg, 'data' => $data]);
    }

    protected function error($msg = '操作失败', $data = [], $code = 1, $http_code = 200): \Illuminate\Http\JsonResponse
    {
        return response()->json(['code' => $code, 'msg' => $msg, 'data' => $data], $http_code);
    }


    protected function layuiTableData(int $count, array $data, array $ext = []): \Illuminate\Http\JsonResponse
    {
        return response()->json(['code' => 0, 'msg' => '', 'count' => $count, 'data' => $data, 'ext' => $ext]);
    }
}
